package com.thinking.dubbo.controller;

import com.thinking.dubbo.api.ResultI18nResponse;
import com.thinking.dubbo.common.TtlThreadUtil;
import com.thinking.dubbo.pojo.Business;
import com.thinking.dubbo.service.DubboService;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @ClassName BusinessController
 * @Description TODO
 * @Author tangsixiang@gmail.com
 * @Date 2023/6/3 18:10
 * @Version 1.0
 */


@RestController
public class BusinessController {

    @Resource
    DubboService dubboService;

    @GetMapping("/query/businessList")
    public List<Business> queryLangDemo(String lang){
      return   dubboService.queryData(lang);
    }

    @GetMapping("/query/giftListAndLang")
    public ResultI18nResponse giftList(String lang, Integer giftId){
        return   ResultI18nResponse.success(dubboService.queryData(lang),lang);
    }

    /***
     *  //dubbo向后传递使用
     * @param giftId
     * @return
     */
    @GetMapping("/query/giftList")
    public ResultI18nResponse giftList(Integer giftId){
        String lang = TtlThreadUtil.getThreadLocal().get();
        return   ResultI18nResponse.success(dubboService.queryData(lang),lang);
    }
    /***
     * 指定相应码
     * @param giftId
     * @return
     */
    @GetMapping("/query/giftCommonList")
    public ResultI18nResponse giftCommonList(Integer giftId,Integer code){
        String lang = TtlThreadUtil.getThreadLocal().get(); //dubbo向后传递使用
        return   ResultI18nResponse.common(dubboService.queryData(lang),lang,code);
    }


    @GetMapping("/query/giftCommonException")
    public ResultI18nResponse giftCommonException(Integer giftId,Integer code){
         return   ResultI18nResponse.error(new NullPointerException("tsx测试空指针验证") );
    }
}
